<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js"></script>
</head>
<body>
    <div id="box">
       
        <child1></child1>
        <child2></child2>
    </div>

    <script>
        // 全局事件总线bus
        var bus = new Vue()


        Vue.component("child1", {
            template:`
            <div>child1-<button @click="handleClick()">详情</button></div>
            `,
            methods:{
                handleClick(){
                    bus.$emit("kerwin", "张三")
                }
            }
        })

        Vue.component("child2", {
            template:`
            <div>child2-订阅者</div>
            `,
            mounted() {
                console.log("生命周期函数-DOM创建完后触发")
                bus.$on("kerwin", (data)=>{
                    console.log("订阅者child2", data)
                })
            },
        })

        var vm = new Vue({
            el:"#box",
            methods: {

            }
        })

    </script>
</body>
</html>